package com.aim.config;

import com.aim.common.util.DateUtils;
import com.aim.entity.system.SysConfig;
import com.aim.service.system.SysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * @AUTO 启动预加载设置
 * @Author AIM
 * @DATE 2019/5/24
 */
@Configuration
public class InitProcessor implements BeanPostProcessor {

    @Autowired
    private SysConfigService configService;

    /**
     * @AUTO 每次启动更新配置表中的系统启动服务时间
     * @DATE 2019/5/24
     */
    @PostConstruct
    public void updateSystemStartDate() {
        SysConfig tmp = new SysConfig();
        tmp.setKey("SYSTEM_TIME");
        SysConfig sysConfig = this.configService.get(tmp);
        if (sysConfig != null) {
            sysConfig.setValue(DateUtils.getDateNow());
            this.configService.update(sysConfig);
        } else {
            tmp.setName("系统启动服务时间");
            tmp.setValue(DateUtils.getDateNow());
            tmp.setSort(0);
            this.configService.save(tmp);
        }
    }
}
